// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-04-01 21:34
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.BinaryAlgorithms;

import java.util.HashMap;
import java.util.Map;

public class singleNumber3 {
    /**
     * 有两个元素只出现一次，其他元素都出现两次->Hash
     */
    public int[] singleNumber(int[] nums) {
        int[] ans = new int[2];
        Map<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            if (map.containsKey(num)) {
                map.remove(num);
            } else {
                map.put(num, 1);
            }
        }
        int idx = 0;
        for (Integer value : map.keySet()) {
            ans[idx++] = value;
        }
        return ans;
    }
}
